﻿using System;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using FanaticGene.WallPaperUtil;

namespace FanaticGene.WallPaper
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static Uri WallPaperVideoFilePathUri { get; set; } = new Uri(@"I:\repo\MyWallPaper\火蓝之心.mp4");

        public MainWindow()
        {
            InitializeComponent();
            InitNotifyIcon();

            this.Width = SystemParameters.WorkArea.Width;
            this.Height = SystemParameters.WorkArea.Height;

            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            WallPaperHelper.Apply(this);
        }

        private void InitNotifyIcon()
        {
            var iconPath = @"test.ico";

            var icon = NotifyIconHelper.CreateNotifyIcon();
            icon.Icon = new System.Drawing.Icon(iconPath);

            var openItem = new MenuItem() { Text = "开始" }; openItem.Click += OpenItem_Click;
            var closeItem = new MenuItem() { Text = "结束" }; closeItem.Click += CloseItem_Click;
            var quitItem = new MenuItem() { Text = "退出" }; quitItem.Click += QuitItem_Click; ;
            var menuItems = new MenuItem[] { openItem, closeItem, quitItem };
            var contextMenu = new System.Windows.Forms.ContextMenu(menuItems);

            icon.Click += Icon_Click;

            icon.ContextMenu = contextMenu;

        }

        private void QuitItem_Click(object sender, EventArgs e)
        {
            App.Current.Shutdown();
        }

        private void Icon_Click(object sender, EventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("Test");
        }

        private void CloseItem_Click(object sender, System.EventArgs e)
        {
            WallPaperHelper.Refresh();
            //Thread.Sleep(1000);
            //App.Current.Shutdown();
        }

        private void OpenItem_Click(object sender, System.EventArgs e)
        {
            WallPaperHelper.Apply(this);
            //System.Windows.Forms.MessageBox.Show("开启");
        }
    }
}
